import 'package:flutter/material.dart';
import 'package:flutterlib/common/constants/constants.dart';
import 'package:flutterlib/common/style/quhui_style.dart';
import 'package:flutterlib/common/utils/navigator_utils.dart';
import 'package:flutterlib/common/utils/utils.dart';
import 'package:flutterlib/model/interest/interest_bean.dart';
import 'package:flutterlib/pages/activity/list/activity_normal_list_widget_page.dart';
import 'package:flutterlib/widgets/quhui_tabbar_widget.dart';
import 'package:flutterlib/widgets/round_underline_tabindicator.dart';


//用于加载内部继承上下拉的页面state的外部容器页面，
//适用于带tabbar，内部是list的页面的改造
class Page extends StatefulWidget {
  final List<InterestBean> interests;

  Page({Key key, this.interests}): super(key : key);

  @override
  PageState createState() => PageState();
}

class PageState extends State<Page>
    with SingleTickerProviderStateMixin {
  // final SettingsStore store =
  // Provider.of<SettingsStore>(currentContext, listen: false);
  // InterestStore interestStore = InterestStore();
  List<Widget> tabPageView = new List();
  List<Widget> tabViews = new List();

  @override
  void initState() {
    super.initState();
    var myInterest = widget.interests;
    tabPageView.add(new ActivityNormalListWidgetPage(name : "全部", interestId: 0, type: 0, ));
    tabViews.add(renderItem("全部", 0));
    tabPageView.add(new ActivityNormalListWidgetPage(name:"招募活动", interestId: 0, type: 1,));
    tabViews.add(renderItem("招募活动", 1));
    if(myInterest != null && myInterest.isNotEmpty) {
      myInterest.asMap().forEach((index, element) {
        tabPageView.add(new ActivityNormalListWidgetPage(
          name: element.name, interestId: element.id, type: 2,));
        tabViews.add(renderItem(element.name, index));
      });
    }
  }

  renderItem(String item, int i) {
    return VgTab(
      child: new Text(
        item,
        style: QuhuiConstant.smallSubText,
        maxLines: 1,
      ),
    );
  }
  @override
  Widget build(BuildContext context) {
    print(context.widget.toStringShort());

        ///绘制顶部 tab 控件
        return new QuhuiTabBarWidget(
          key: ValueKey(context.widget.toStringShort()),
          type: TabType.top,
          tabItems: tabViews,
          tabBarType: 2,
          resizeToAvoidBottomPadding: false,
          tabViews: tabPageView,
          backgroundColor: QuhuiColors.mainBackgroundColor,
          indicatorColor: QuhuiColors.mainThemeColor,

          title: Text('活动', style: QuhuiConstant.normalTextBold),
          // leading: Material(
          //   color: Colors.transparent,
          //   child: InkWell(
          //     borderRadius: const BorderRadius.all(
          //       Radius.circular(32.0),
          //     ),
          //     onTap: () {},
          //     child: Icon(
          //       Icons.search,
          //       color: Colors.black,
          //     ),
          //   ),
          // ),
          actions: <Widget>[
            Material(
              color: Colors.transparent,
              child: InkWell(
                onTap: () {
                  NavigatorUtils.gotoActivityMine(context);
                },
                child: Row(
                  children: <Widget>[
                    Text(
                      "我的活动",
                      style: QuhuiConstant.smallTextBold,
                    ),
                    Icon(
                      Icons.arrow_forward_ios,
                      color: Colors.black,
                    )
                  ],
                ),
              ),
            ),
          ],
          onPageChanged: (index) {},
        );
  }
}
